package client.GUI.login;

import client.GUI.GUIClient;
import java.awt.*;
import javax.swing.*;

import client.GUI.GUIConstants;


import java.awt.event.*;

/**
 * Creates a panel in which the user can recreate a password
 * in case it was forgotten
 */
public class LostPasswordPanel extends JPanel implements ActionListener
{
	private static LostPasswordPanel instance = null;
	
    JLabel lpLabel1, lpLabel2, outputLabel, uNLabel;
    JTextField nField;
    JButton back, submit;
    
    /**
     * Default constructor, creates, arranges and sizes
     * the components
     */
    private LostPasswordPanel() {
        this.setSize(1024,768);
        this.setLayout(null);
        
        this.setBackground(GUIConstants.Background_Color);
        
        lpLabel1 = new JLabel("Forgot Your Password?");
        lpLabel2 = new JLabel("enter your username and your password will be sent to your email address");
        outputLabel = new JLabel();
        uNLabel = new JLabel("Username:");
        nField = new JTextField();
        back = new JButton("BACK");
        submit = new JButton("SUBMIT");
        
        lpLabel1.setBounds(312, 200, 400, 100);
        lpLabel1.setFont(GUIConstants.Big_Font);
        lpLabel1.setForeground(GUIConstants.Text_Color);
        
        lpLabel2.setBounds(212, 300, 600, 50);
        lpLabel2.setFont(GUIConstants.Little_Font);
        lpLabel2.setForeground(GUIConstants.Text_Color);
        
        uNLabel.setBounds(312, 400, 100, 25);
        uNLabel.setForeground(GUIConstants.Text_Color);
        uNLabel.setHorizontalAlignment(JLabel.RIGHT);
        
        nField.setBounds(412, 400, 250, 25);
        
        back.setBounds(387, 500, 100, 50);
        
        submit.setBounds(537, 500, 100, 50); 
        
        this.add(lpLabel1);
        this.add(lpLabel2);
        this.add(uNLabel);
        this.add(nField);
        this.add(submit);
        this.add(back);
        
        submit.addActionListener(this);
        back.addActionListener(this);
    }
    
    /**
     * Checks for prexisting instances of LostPasswordPanel
     * 
     * @return instance - The LostPasswordPanel to be used
     */
    public static LostPasswordPanel getInstance() {
    	if (instance == null) {
    		instance = new LostPasswordPanel();
    	}
    	
    	return instance;
    }
    
    /**
     * Sets the username field 
     * 
     * @param uName		The String containing the username
     */
    public void setFields(String uName) {
        nField.setText(uName);
        nField.setEditable(false);
    }
    
    /**
     * Checks for actions and performs appropriate tasks
     */
    public void actionPerformed(ActionEvent e) {
    	if (e.getSource() == back) {
    		System.out.println("back");
    		GUIClient.getInstance().displayLogin();
    	}
    }
}
